{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# Convert prediction results to labels(将预测结果转为标签)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "import math\n",
    "import random\n",
    "\n",
    "from pandas import set_option"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# mpl.rcParams['font.sans-serif'] = ['SimHei']\n",
    "# plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签\n",
    "# plt.rcParams['axes.unicode_minus']=False #用来正常显示负号\n",
    "set_option(\"display.max_rows\", 15)\n",
    "set_option('display.width', 400)\n",
    "np.set_printoptions(suppress=True, threshold=5000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# 使用GPU训练时候，打开下面注释\n",
    "os.environ['CUDA_VISIBLE_DEVICES']='0'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# Preparation work (data processing, result saving location definition)(准备工作,数据处理，结果保存位置定义)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## Input prediction result dataset location(输入结果数据集位置)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "usual_logs_DataPath = 'facies_csv_results/bigru-self-atten_test/'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "facies_csv_results/bigru-self-atten_test/YX-58井_facies_vectors_0.1_7_Pred_R_04271055.csv\n"
     ]
    }
   ],
   "source": [
    "filename_usual_logs = 'YX-58井_facies_vectors_0.1_7_Pred_R_04271055.csv'   # 青山口组；  泉头组\n",
    "usual_logs_DataPath = os.path.join(usual_logs_DataPath,filename_usual_logs)\n",
    "print(usual_logs_DataPath)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "outputs": [],
   "source": [
    "well_no = \"YX-58\""
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## Storage location of lithofacies dataset（岩相数据集保存位置）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "facies_logs_DataPath = 'facies_csv_results/'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "method = os.path.dirname(usual_logs_DataPath).split(\"/\")[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "filename_facies_logs =  'facies_pred_' + method + '.csv'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "'facies_pred_bigru-self-atten_test.csv'"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "filename_facies_logs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "facies_logs_DataPath = os.path.join(facies_logs_DataPath,filename_facies_logs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "outputs": [
    {
     "data": {
      "text/plain": "'facies_csv_results/facies_pred_bigru-self-atten_test.csv'"
     },
     "execution_count": 117,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "facies_logs_DataPath"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# Lithographic data conversion（岩相数据标定)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## ## Read input curves and expert lithofacies classification data（读取输入曲线和专家岩相分类数据)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "input_vector_data = pd.read_csv(usual_logs_DataPath,engine='python',encoding='GBK',sep = ',')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "       DEPTH        GR      CNL       DT     DEN    MSFL      RS      RD  Prediction  Facies\n0     2013.3  141.5902  22.3832  98.4706  2.4714  0.6528  0.6723  0.6273           2       1\n1     2013.4  138.6362  20.9666  95.5322  2.4768  0.6187  0.6664  0.6202           2       1\n2     2013.5  133.8810  19.0250  91.1610  2.4840  0.5940  0.6772  0.6301           2       1\n3     2013.6  127.3738  17.7330  86.7578  2.4968  0.6701  0.7177  0.6745           2       1\n4     2013.7  120.9938  16.9672  83.8078  2.5114  0.8415  0.7759  0.7408           2       1\n...      ...       ...      ...      ...     ...     ...     ...     ...         ...     ...\n1077  2121.0  138.9920  19.5630  91.9960  2.5790  0.8238  0.7333  0.6824           1       3\n1078  2121.1  133.5352  19.7814  89.8688  2.5622  0.7972  0.7630  0.7131           1       6\n1079  2121.2  126.5028  19.7904  87.2976  2.5448  0.8582  0.8096  0.7632           1       6\n1080  2121.3  120.2804  19.4012  84.6108  2.5292  1.0068  0.8679  0.8274           2       6\n1081  2121.4  116.5122  18.5996  82.2284  2.5176  1.1494  0.9291  0.8960           2       6\n\n[1082 rows x 10 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>DEPTH</th>\n      <th>GR</th>\n      <th>CNL</th>\n      <th>DT</th>\n      <th>DEN</th>\n      <th>MSFL</th>\n      <th>RS</th>\n      <th>RD</th>\n      <th>Prediction</th>\n      <th>Facies</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2013.3</td>\n      <td>141.5902</td>\n      <td>22.3832</td>\n      <td>98.4706</td>\n      <td>2.4714</td>\n      <td>0.6528</td>\n      <td>0.6723</td>\n      <td>0.6273</td>\n      <td>2</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2013.4</td>\n      <td>138.6362</td>\n      <td>20.9666</td>\n      <td>95.5322</td>\n      <td>2.4768</td>\n      <td>0.6187</td>\n      <td>0.6664</td>\n      <td>0.6202</td>\n      <td>2</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2013.5</td>\n      <td>133.8810</td>\n      <td>19.0250</td>\n      <td>91.1610</td>\n      <td>2.4840</td>\n      <td>0.5940</td>\n      <td>0.6772</td>\n      <td>0.6301</td>\n      <td>2</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2013.6</td>\n      <td>127.3738</td>\n      <td>17.7330</td>\n      <td>86.7578</td>\n      <td>2.4968</td>\n      <td>0.6701</td>\n      <td>0.7177</td>\n      <td>0.6745</td>\n      <td>2</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2013.7</td>\n      <td>120.9938</td>\n      <td>16.9672</td>\n      <td>83.8078</td>\n      <td>2.5114</td>\n      <td>0.8415</td>\n      <td>0.7759</td>\n      <td>0.7408</td>\n      <td>2</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>1077</th>\n      <td>2121.0</td>\n      <td>138.9920</td>\n      <td>19.5630</td>\n      <td>91.9960</td>\n      <td>2.5790</td>\n      <td>0.8238</td>\n      <td>0.7333</td>\n      <td>0.6824</td>\n      <td>1</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>1078</th>\n      <td>2121.1</td>\n      <td>133.5352</td>\n      <td>19.7814</td>\n      <td>89.8688</td>\n      <td>2.5622</td>\n      <td>0.7972</td>\n      <td>0.7630</td>\n      <td>0.7131</td>\n      <td>1</td>\n      <td>6</td>\n    </tr>\n    <tr>\n      <th>1079</th>\n      <td>2121.2</td>\n      <td>126.5028</td>\n      <td>19.7904</td>\n      <td>87.2976</td>\n      <td>2.5448</td>\n      <td>0.8582</td>\n      <td>0.8096</td>\n      <td>0.7632</td>\n      <td>1</td>\n      <td>6</td>\n    </tr>\n    <tr>\n      <th>1080</th>\n      <td>2121.3</td>\n      <td>120.2804</td>\n      <td>19.4012</td>\n      <td>84.6108</td>\n      <td>2.5292</td>\n      <td>1.0068</td>\n      <td>0.8679</td>\n      <td>0.8274</td>\n      <td>2</td>\n      <td>6</td>\n    </tr>\n    <tr>\n      <th>1081</th>\n      <td>2121.4</td>\n      <td>116.5122</td>\n      <td>18.5996</td>\n      <td>82.2284</td>\n      <td>2.5176</td>\n      <td>1.1494</td>\n      <td>0.9291</td>\n      <td>0.8960</td>\n      <td>2</td>\n      <td>6</td>\n    </tr>\n  </tbody>\n</table>\n<p>1082 rows × 10 columns</p>\n</div>"
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "input_vector_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# 针对输入曲线\n",
    "depth_cols = 'DEPTH'\n",
    "# 针对岩相曲线\n",
    "pred_col = 'Prediction'\n",
    "depth_begin_col = '顶深'\n",
    "depth_end_col = '底深'\n",
    "facies_col = '岩性'\n",
    "well_name_col = '井号'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "resolution = 50\n",
    "resolution_ratio = 1 / resolution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "(2014.2, 1082)"
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "input_vector_data[depth_cols][9],len(input_vector_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "begin_depth_list = []\n",
    "end_depth_list = []\n",
    "pred_list = []\n",
    "current_row_id = 0\n",
    "cursor_facies_id = input_vector_data[pred_col][0]\n",
    "cursor_depth = input_vector_data[depth_cols][0]\n",
    "for depth in range(len(input_vector_data)):\n",
    "    curent_depth = input_vector_data[depth_cols][depth]\n",
    "    current_facies = input_vector_data[pred_col][depth]\n",
    "    if cursor_facies_id !=  input_vector_data[pred_col][depth]:\n",
    "        begin_depth_list.append(cursor_depth)\n",
    "        end_depth_list.append(curent_depth)\n",
    "        pred_list.append(cursor_facies_id)\n",
    "        cursor_facies_id = current_facies\n",
    "        cursor_depth = curent_depth\n",
    "    else:\n",
    "        pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "outputs": [
    {
     "data": {
      "text/plain": "(47, 47, 47)"
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(begin_depth_list),len(end_depth_list),len(pred_list)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "facies_vector = input_vector_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "if well_name_col in facies_vector.columns:\n",
    "    pd_well_no = np.full(len(input_vector_data),facies_vector[well_name_col][0])\n",
    "else:\n",
    "    pd_well_no = np.full(len(input_vector_data),well_no)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "array(['YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58', 'YX-58',\n       'YX-58', 'YX-58', 'YX-58', 'YX-58'], dtype='<U5')"
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd_well_no"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## 岩相类别符号转换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# facies_label = np.unique(facies_vector[facies_col])\n",
    "'''\n",
    "facies_label = [\n",
    "    \"High organic matter layered shale lithofacies\",\n",
    "    \"High organic striated layered shale lithofacies\",\n",
    "    \"Medium organic striated layered shale lithofacies\",\n",
    "    \"Low organic matter striated layered shale lithofacies\",\n",
    "    \"Medium to low organic matter massive dolomite lithofacies\",\n",
    "    \"Low organic matter massive shell limestone lithofacies\"\n",
    "    \"Low organic matter massive siltstone lithofacies\"\n",
    "]\n",
    "'''\n",
    "facies_labels = ['高有机质层状页岩相', '高有机质纹层状页岩相','中有机质纹层状页岩相','低有机质纹层状页岩相',\n",
    "                '中低有机质块状白云岩相', '低有机质块状介壳灰岩相', '低有机质块状粉砂岩相']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "(2300, 2400)"
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# init varible\n",
    "depth_min = 2300\n",
    "depth_max = 2400\n",
    "math.floor(depth_min),math.ceil(depth_max)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "scrolled": true,
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "9"
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# for i in range(math.floor(depth_min),math.ceil(depth_max)+1):\n",
    "#     print(i)\n",
    "len(facies_labels[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "label_max_lenth = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "for i in range(len(facies_labels)):\n",
    "    if label_max_lenth < len(facies_labels[i]):\n",
    "        label_max_lenth = len(facies_labels[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "1082"
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(input_vector_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "def generate_random_str(randomlength):\n",
    "    \"\"\"\n",
    "    生成一个指定长度的随机字符串\n",
    "    \"\"\"\n",
    "    random_str = ''\n",
    "    base_str = 'ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789'\n",
    "    length = len(base_str) - 1\n",
    "    for i in range(randomlength):\n",
    "        random_str += base_str[random.randint(0, length)]\n",
    "    return random_str\n",
    "# ————————————————\n",
    "# 版权声明：本文为CSDN博主「geerniya」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。\n",
    "# 原文链接：https://blog.csdn.net/geerniya/java/article/details/78497765"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "'HHFMkQLUxNF'"
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fill_label = generate_random_str(label_max_lenth)\n",
    "fill_label"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "facies_list = np.full(len(pred_list),\"no_label\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "outputs": [
    {
     "data": {
      "text/plain": "(47, 47, 47)"
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(begin_depth_list),len(end_depth_list),len(pred_list)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {
    "scrolled": true,
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "depth_min,depth_max: 2013.3 2014.2\n",
      "No_0layers: 中有机质纹层状页\n",
      "depth_min,depth_max: 2014.2 2014.7\n",
      "No_1layers: 低有机质块状粉砂\n",
      "depth_min,depth_max: 2014.7 2015.6\n",
      "No_2layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2015.6 2016.4\n",
      "No_3layers: 中有机质纹层状页\n",
      "depth_min,depth_max: 2016.4 2017.6\n",
      "No_4layers: 低有机质纹层状页\n",
      "depth_min,depth_max: 2017.6 2027.7\n",
      "No_5layers: 中有机质纹层状页\n",
      "depth_min,depth_max: 2027.7 2032.8\n",
      "No_6layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2032.8 2033.4\n",
      "No_7layers: 低有机质块状粉砂\n",
      "depth_min,depth_max: 2033.4 2034.3\n",
      "No_8layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2034.3 2034.9\n",
      "No_9layers: 中有机质纹层状页\n",
      "depth_min,depth_max: 2034.9 2036.1\n",
      "No_10layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2036.1 2037.2\n",
      "No_11layers: 中有机质纹层状页\n",
      "depth_min,depth_max: 2037.2 2039.1\n",
      "No_12layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2039.1 2040.0\n",
      "No_13layers: 低有机质块状粉砂\n",
      "depth_min,depth_max: 2040.0 2040.9\n",
      "No_14layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2040.9 2042.0\n",
      "No_15layers: 中有机质纹层状页\n",
      "depth_min,depth_max: 2042.0 2044.2\n",
      "No_16layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2044.2 2044.7\n",
      "No_17layers: 中有机质纹层状页\n",
      "depth_min,depth_max: 2044.7 2049.4\n",
      "No_18layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2049.4 2049.8\n",
      "No_19layers: 中低有机质块状白\n",
      "depth_min,depth_max: 2049.8 2054.9\n",
      "No_20layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2054.9 2055.2\n",
      "No_21layers: 中低有机质块状白\n",
      "depth_min,depth_max: 2055.2 2061.2\n",
      "No_22layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2061.2 2061.5\n",
      "No_23layers: 中有机质纹层状页\n",
      "depth_min,depth_max: 2061.5 2061.7\n",
      "No_24layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2061.7 2062.2\n",
      "No_25layers: 中有机质纹层状页\n",
      "depth_min,depth_max: 2062.2 2065.4\n",
      "No_26layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2065.4 2065.5\n",
      "No_27layers: 中有机质纹层状页\n",
      "depth_min,depth_max: 2065.5 2068.3\n",
      "No_28layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2068.3 2068.7\n",
      "No_29layers: 低有机质块状粉砂\n",
      "depth_min,depth_max: 2068.7 2073.4\n",
      "No_30layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2073.4 2074.0\n",
      "No_31layers: 低有机质块状粉砂\n",
      "depth_min,depth_max: 2074.0 2077.9\n",
      "No_32layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2077.9 2078.8\n",
      "No_33layers: 中有机质纹层状页\n",
      "depth_min,depth_max: 2078.8 2080.3\n",
      "No_34layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2080.3 2080.4\n",
      "No_35layers: 中有机质纹层状页\n",
      "depth_min,depth_max: 2080.4 2080.5\n",
      "No_36layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2080.5 2080.9\n",
      "No_37layers: 低有机质块状粉砂\n",
      "depth_min,depth_max: 2080.9 2092.0\n",
      "No_38layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2092.0 2092.1\n",
      "No_39layers: 高有机质层状页岩\n",
      "depth_min,depth_max: 2092.1 2093.5\n",
      "No_40layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2093.5 2094.1\n",
      "No_41layers: 高有机质层状页岩\n",
      "depth_min,depth_max: 2094.1 2101.0\n",
      "No_42layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2101.0 2103.0\n",
      "No_43layers: 高有机质层状页岩\n",
      "depth_min,depth_max: 2103.0 2110.9\n",
      "No_44layers: 高有机质纹层状页\n",
      "depth_min,depth_max: 2110.9 2111.6\n",
      "No_45layers: 高有机质层状页岩\n",
      "depth_min,depth_max: 2111.6 2121.3\n",
      "No_46layers: 高有机质纹层状页\n",
      "Label Work Finished!\n"
     ]
    }
   ],
   "source": [
    "\n",
    "lower_depth_index = 0\n",
    "# 深度列标尺初始化\n",
    "# current_depth = input_vector_data[depth_cols][0]\n",
    "facies_label_m_pred = 0\n",
    "real_class_num = len(facies_labels)\n",
    "for i in range(len(pred_list)):\n",
    "    depth_min = begin_depth_list[i]\n",
    "    depth_max = end_depth_list[i]\n",
    "    current_facies_label = pred_list[i]\n",
    "    if facies_label_m_pred < 0 or facies_label_m_pred >= real_class_num:\n",
    "        current_facies_id = \"unpredictable\"\n",
    "    else:\n",
    "        current_facies_id = facies_labels[current_facies_label]\n",
    "        # current_well_no = facies_vector[well_name_col][i]\n",
    "        print(\"depth_min,depth_max:\",depth_min,depth_max)\n",
    "        facies_list[i] = current_facies_id\n",
    "        print(\"No_\" + str(i) + \"layers\" + \": \" + facies_list[i])\n",
    "\n",
    "print(\"Label Work Finished!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# facies_list len(begin_depth_list),len(end_depth_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# wellname_colunm_data = pd.DataFrame(pd_well_no, columns=[\"Well Name\"])\n",
    "begin_depth_colunm_data = pd.DataFrame(begin_depth_list, columns=[\"begin depth\"])\n",
    "end_depth_colunm_data = pd.DataFrame(end_depth_list, columns=[\"end depth\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "facies_colunm_data = pd.DataFrame(facies_list, columns=[\"Facies\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "      Facies\n0   中有机质纹层状页\n1   低有机质块状粉砂\n2   高有机质纹层状页\n3   中有机质纹层状页\n4   低有机质纹层状页\n..       ...\n42  高有机质纹层状页\n43  高有机质层状页岩\n44  高有机质纹层状页\n45  高有机质层状页岩\n46  高有机质纹层状页\n\n[47 rows x 1 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Facies</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>中有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>低有机质块状粉砂</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>高有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>中有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>低有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>42</th>\n      <td>高有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>43</th>\n      <td>高有机质层状页岩</td>\n    </tr>\n    <tr>\n      <th>44</th>\n      <td>高有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>45</th>\n      <td>高有机质层状页岩</td>\n    </tr>\n    <tr>\n      <th>46</th>\n      <td>高有机质纹层状页</td>\n    </tr>\n  </tbody>\n</table>\n<p>47 rows × 1 columns</p>\n</div>"
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "facies_colunm_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "47"
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# wellname_colunm_data\n",
    "len(facies_colunm_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "pd_data = pd.concat([begin_depth_colunm_data, end_depth_colunm_data ,facies_colunm_data],axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "    begin depth  end depth    Facies\n0        2013.3     2014.2  中有机质纹层状页\n1        2014.2     2014.7  低有机质块状粉砂\n2        2014.7     2015.6  高有机质纹层状页\n3        2015.6     2016.4  中有机质纹层状页\n4        2016.4     2017.6  低有机质纹层状页\n..          ...        ...       ...\n42       2094.1     2101.0  高有机质纹层状页\n43       2101.0     2103.0  高有机质层状页岩\n44       2103.0     2110.9  高有机质纹层状页\n45       2110.9     2111.6  高有机质层状页岩\n46       2111.6     2121.3  高有机质纹层状页\n\n[47 rows x 3 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>begin depth</th>\n      <th>end depth</th>\n      <th>Facies</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2013.3</td>\n      <td>2014.2</td>\n      <td>中有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2014.2</td>\n      <td>2014.7</td>\n      <td>低有机质块状粉砂</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2014.7</td>\n      <td>2015.6</td>\n      <td>高有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2015.6</td>\n      <td>2016.4</td>\n      <td>中有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2016.4</td>\n      <td>2017.6</td>\n      <td>低有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>42</th>\n      <td>2094.1</td>\n      <td>2101.0</td>\n      <td>高有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>43</th>\n      <td>2101.0</td>\n      <td>2103.0</td>\n      <td>高有机质层状页岩</td>\n    </tr>\n    <tr>\n      <th>44</th>\n      <td>2103.0</td>\n      <td>2110.9</td>\n      <td>高有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>45</th>\n      <td>2110.9</td>\n      <td>2111.6</td>\n      <td>高有机质层状页岩</td>\n    </tr>\n    <tr>\n      <th>46</th>\n      <td>2111.6</td>\n      <td>2121.3</td>\n      <td>高有机质纹层状页</td>\n    </tr>\n  </tbody>\n</table>\n<p>47 rows × 3 columns</p>\n</div>"
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "save_no_label_pred_info = False\n",
    "if save_no_label_pred_info == True:\n",
    "    data_save = pd_data[pd_data[\"Facies\"] != \"no_label\"].reset_index(drop=True)\n",
    "else:\n",
    "    data_save = pd_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "    begin depth  end depth    Facies\n0        2013.3     2014.2  中有机质纹层状页\n1        2014.2     2014.7  低有机质块状粉砂\n2        2014.7     2015.6  高有机质纹层状页\n3        2015.6     2016.4  中有机质纹层状页\n4        2016.4     2017.6  低有机质纹层状页\n..          ...        ...       ...\n42       2094.1     2101.0  高有机质纹层状页\n43       2101.0     2103.0  高有机质层状页岩\n44       2103.0     2110.9  高有机质纹层状页\n45       2110.9     2111.6  高有机质层状页岩\n46       2111.6     2121.3  高有机质纹层状页\n\n[47 rows x 3 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>begin depth</th>\n      <th>end depth</th>\n      <th>Facies</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2013.3</td>\n      <td>2014.2</td>\n      <td>中有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2014.2</td>\n      <td>2014.7</td>\n      <td>低有机质块状粉砂</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2014.7</td>\n      <td>2015.6</td>\n      <td>高有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2015.6</td>\n      <td>2016.4</td>\n      <td>中有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2016.4</td>\n      <td>2017.6</td>\n      <td>低有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>42</th>\n      <td>2094.1</td>\n      <td>2101.0</td>\n      <td>高有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>43</th>\n      <td>2101.0</td>\n      <td>2103.0</td>\n      <td>高有机质层状页岩</td>\n    </tr>\n    <tr>\n      <th>44</th>\n      <td>2103.0</td>\n      <td>2110.9</td>\n      <td>高有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>45</th>\n      <td>2110.9</td>\n      <td>2111.6</td>\n      <td>高有机质层状页岩</td>\n    </tr>\n    <tr>\n      <th>46</th>\n      <td>2111.6</td>\n      <td>2121.3</td>\n      <td>高有机质纹层状页</td>\n    </tr>\n  </tbody>\n</table>\n<p>47 rows × 3 columns</p>\n</div>"
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_save"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# Mark Results Save(标记结果保存)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## Result file header information(结果文件文件头信息)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# fianl_facies_logs = well_name + '_'+ str(begin_depth) + '-'+ str(end_depth) +'_facies_vectors_' + str(1/resolution)+ '.csv' \n",
    "fianl_facies_logs = well_no + '_facies_vectors_pred.csv'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "YX-58_facies_vectors_pred.csv\n"
     ]
    }
   ],
   "source": [
    "print(fianl_facies_logs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## Result dataset save location(结果数据集保存位置)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "Using_DataPath = 'facies_data/train/'\n",
    "if not os.path.exists(Using_DataPath):\n",
    "    os.makedirs(Using_DataPath)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# Using_DataPath = os.path.join(Using_DataPath,fianl_facies_logs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "0.1"
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resolution_ratio = 1 / resolution\n",
    "resolution_ratio"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## The saved result curve(保存的结果曲线)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "    begin depth  end depth    Facies\n0        2013.3     2014.2  中有机质纹层状页\n1        2014.2     2014.7  低有机质块状粉砂\n2        2014.7     2015.6  高有机质纹层状页\n3        2015.6     2016.4  中有机质纹层状页\n4        2016.4     2017.6  低有机质纹层状页\n..          ...        ...       ...\n42       2094.1     2101.0  高有机质纹层状页\n43       2101.0     2103.0  高有机质层状页岩\n44       2103.0     2110.9  高有机质纹层状页\n45       2110.9     2111.6  高有机质层状页岩\n46       2111.6     2121.3  高有机质纹层状页\n\n[47 rows x 3 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>begin depth</th>\n      <th>end depth</th>\n      <th>Facies</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2013.3</td>\n      <td>2014.2</td>\n      <td>中有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2014.2</td>\n      <td>2014.7</td>\n      <td>低有机质块状粉砂</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2014.7</td>\n      <td>2015.6</td>\n      <td>高有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2015.6</td>\n      <td>2016.4</td>\n      <td>中有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2016.4</td>\n      <td>2017.6</td>\n      <td>低有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>42</th>\n      <td>2094.1</td>\n      <td>2101.0</td>\n      <td>高有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>43</th>\n      <td>2101.0</td>\n      <td>2103.0</td>\n      <td>高有机质层状页岩</td>\n    </tr>\n    <tr>\n      <th>44</th>\n      <td>2103.0</td>\n      <td>2110.9</td>\n      <td>高有机质纹层状页</td>\n    </tr>\n    <tr>\n      <th>45</th>\n      <td>2110.9</td>\n      <td>2111.6</td>\n      <td>高有机质层状页岩</td>\n    </tr>\n    <tr>\n      <th>46</th>\n      <td>2111.6</td>\n      <td>2121.3</td>\n      <td>高有机质纹层状页</td>\n    </tr>\n  </tbody>\n</table>\n<p>47 rows × 3 columns</p>\n</div>"
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_save"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Algorithm is Finished!!\n"
     ]
    }
   ],
   "source": [
    "# 输出txt\n",
    "# data_save.to_csv(os.path.join(Using_DataPath,fianl_facies_logs),mode='w',float_format='%.4f',sep='\\t',index=None,header=True)\n",
    "data_save.to_csv(os.path.join(Using_DataPath,fianl_facies_logs),mode='w',float_format='%.4f',encoding='GBK',index=None,header=True)\n",
    "print(\"Algorithm is Finished!!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# if paly_music == True:\n",
    "#     mixer.init()\n",
    "#     music_path = \"music/\"\n",
    "#     file = \"MISIA - 星のように.mp3\"\n",
    "#     music_file = os.path.join(music_path,file)\n",
    "#     mixer.music.load(music_file)\n",
    "#     mixer.music.play()\n",
    "#     time.sleep(6)\n",
    "#     mixer.music.stop()\n",
    "#         # exit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "python310",
   "language": "python",
   "display_name": "Python 310 (ipykernel)"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "270.2px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}